import 'package:bruno/bruno.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:whale/pages/means/main/widgets/select.dart';

import '../../../helper/utils/util.dart';
import 'index.dart';
import 'widgets/fair_data.dart';
import 'widgets/hot_data.dart';
import 'widgets/level_data.dart';
import 'widgets/risk_data.dart';
import 'widgets/trend_data.dart';
import 'widgets/type_data.dart';
import 'widgets/widgets.dart';

class WatchPage extends StatelessWidget {
  WatchPage({Key? key}) : super(key: key);
  final controller = Get.put(WatchController());
  final state = Get.find<WatchController>().state;
  // 主视图
  Widget _buildView() {
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 15.r, vertical: 10.r),
      child: ListView(
        children: [
          TotalDataView(),
          HotDataView(),
          RiskDataView(),
          TypeDataView(),
          LevelDataView(),
          FairDataView(),
          TrendDataView()
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<WatchController>(
      builder: (_) {
        return Scaffold(
          backgroundColor: const Color(0xffF4F6FA),
          appBar: AppBar(
            title: Text(
              '监测',
              style: TextStyle(
                  color: ColorsUtil.title,
                  fontSize: 17.r,
                  fontWeight: FontWeight.bold),
            ),
            centerTitle: true,
            backgroundColor: Colors.white,
            elevation: 0,
            actions: [
              IconButton(
                  onPressed: () {
                    Get.to(HotDataView());
                  },
                  icon: const Icon(IconUtil.search))
            ],
            bottom: PreferredSize(
              preferredSize: Size.fromHeight(100.r),
              child: Column(
                children: [
                  BrnTabBar(
                      controller: state.titleTc,
                      labelStyle:
                          TextStyle(color: ColorsUtil.theme, fontSize: 14.r),
                      unselectedLabelStyle:
                          TextStyle(color: ColorsUtil.title, fontSize: 14.r),
                      tabs: ['全局', '政策措施', '招标采购']
                          .asMap()
                          .map(
                            (key, value) => MapEntry(
                              key,
                              BadgeTab(text: value),
                            ),
                          )
                          .values
                          .toList()),
                  Container(
                    height: 1,
                    width: 1.sw,
                    color: const Color(0xffE1E4EB),
                  ),
                  Container(
                    color: Colors.white,
                    child: MeansSelectView(
                      titles: state.selectionTitles ?? [],
                      complete: controller.selectionResults,
                    ),
                  ),
                ],
              ),
            ),
          ),
          body: SafeArea(
            child: _buildView(),
          ),
        );
      },
    );
  }
}
